home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6210 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: newshub.ccs.yorku.ca!oz
  2. From: oz@nexus.yorku.ca (ozan s. yigit)
  3. Newsgroups: comp.lang.misc,comp.lang.perl.misc,comp.lang.tcl,comp.lang.c,comp.lang.java
  4. Subject: Re: Readable Perl (was: Re: Relative Speed of Perl vs. Tcl vs. C)
  5. Date: 22 Feb 96 23:58:18
  6. Organization: The Electric Skillet
  7. Message-ID: <OZ.96Feb22235818@nexus.yorku.ca>
  8. NNTP-Posting-Host: nexus.yorku.ca
  9.  
  10. some people seem to dislike tiny code examples, which seems rather
  11. strange: in capable hands, they speak volumes. it is true that not
  12. every posting includes such a gem, but i think there is room for even
  13. the good old fib. on the essay side, very few languages come with the
  14. type of tour-de-force tutorial [1] sather people have been able
  15. to put together, not sure why...
  16.  
  17. anyway, just for the kicks, here is one fib due to kent dbybig. enjoy.
  18.  
  19. ;;; fib with peano arithmetic (using numbers) with call/cc
  20.  
  21. (define addc
  22.    (rec addc
  23.       (lambda (x y k)
  24.          (if (zero? y)
  25.              (k x)
  26.              (addc (1+ x) (1- y) k)))))
  27.  
  28. (define fibc
  29.    (rec fibc
  30.       (lambda (x c)
  31.          (if (zero? x)
  32.              (c 0)
  33.              (if (zero? (1- x))
  34.                  (c 1)
  35.                  (addc (call/cc (lambda (c) (fibc (1- x) c)))
  36.                        (call/cc (lambda (c) (fibc (1- (1- x)) c)))
  37.                        c))))))
  38.  
  39.  
  40. oz
  41. ---
  42. [1] Michael Philippsen
  43.     Sather 1.0 Tutorial
  44.     International Computer Science Institute TR-94-062
  45.     December 1994
  46.